﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Data;
using KC.ExtensionMethods;

namespace KC.Tests.KC.ExtensionMethods
{
	[TestClass]
	public class DataObjects
	{
		[TestMethod]
		public void AddAtBeginningTest()
		{
			DataTable dt = new DataTable();
			dt.Columns.Add("col1", "".GetType());
			dt.Columns.Add("col2", "".GetType());
			dt.Columns.AddAt(new DataColumn("col0", 0.GetType()), 0);

			Assert.AreEqual(dt.Columns[0].ColumnName, "col0");
			Assert.AreEqual(dt.Columns[1].ColumnName, "col1");
			Assert.AreEqual(dt.Columns[2].ColumnName, "col2");
		}
		[TestMethod]
		public void AddAtMiddleTest()
		{
			DataTable dt = new DataTable();
			dt.Columns.Add("col1", "".GetType());
			dt.Columns.Add("col2", "".GetType());
			dt.Columns.AddAt(new DataColumn("col1_5", 0.GetType()), 1);
			Assert.AreEqual(dt.Columns[0].ColumnName, "col1");
			Assert.AreEqual(dt.Columns[1].ColumnName, "col1_5");
			Assert.AreEqual(dt.Columns[2].ColumnName, "col2");
		}
		[TestMethod]
		public void AddAtEndTest()
		{
			DataTable dt = new DataTable();
			dt.Columns.Add("col1", "".GetType());
			dt.Columns.Add("col2", "".GetType());
			dt.Columns.AddAt(new DataColumn("col3", 0.GetType()), 2);
			Assert.AreEqual(dt.Columns[0].ColumnName, "col1");
			Assert.AreEqual(dt.Columns[1].ColumnName, "col2");
			Assert.AreEqual(dt.Columns[2].ColumnName, "col3");
		}
		[TestMethod]
		[ExpectedException(typeof(NullReferenceException))]
		public void AddAtNullColTest()
		{
			DataTable dt = null;
			dt.Columns.AddAt(new DataColumn("", "".GetType()), 0);
		}
		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void AddAtNullDcTest()
		{
			new DataTable().Columns.AddAt(null, 0);
		}
		[TestMethod]
		[ExpectedException(typeof(ArgumentOutOfRangeException))]
		public void AddAtIndexRangeTest()
		{
			DataTable dt = new DataTable();
			dt.Columns.Add("0","".GetType());
			dt.Columns.Add("1",1.GetType());
			dt.Columns.AddAt(new DataColumn("2","".GetType()), 3);
		}
	}
}
